package com.mall.controller;


import com.mall.dto.OmsOrderReturnApplyDto;
import com.mall.pageResult.PageResult;
import com.mall.pojo.OmsOrderReturnApply;
import com.mall.pojo.OmsUpdateStatusParam;
import com.mall.service.OmsOrderReturnApplyService;
import com.mall.utils.Result;
import com.mall.vo.OmsOrderReturnApplyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/returnApply")
public class OmsOrderReturnApplyController {
    @Autowired
    private OmsOrderReturnApplyService omsOrderReturnApplyService;

    /**
     * 修改退货申请状态
     * @param id
     * @return
     */
    @PostMapping("/update/status/{id}")
    public Result<Integer> updateOrderReturnApplyStatus(@PathVariable Integer id,
                                                        @RequestBody OmsUpdateStatusParam statusParam) {

        //调用方法对收货状态进行修改
       Integer updateRe =  omsOrderReturnApplyService.updateOrderReturnApplyStatus(id,statusParam);

       return Result.success(updateRe,"操作成功");
    }

    /**
     * 批量删除退货申请
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public Result<Integer> deleteOrderReturnApply(@RequestParam("ids") List<Integer> ids){
        //调用方法进行删除
       Integer deleteNum  =  omsOrderReturnApplyService.deleteOrderReturnApply(ids);

       if (deleteNum == 0){
            return Result.error(deleteNum,"操作失败");
       }
       return Result.success(deleteNum,"操作成功");




    }



    /**
     * 获取订单退货申请处理详情
     *
     */
    @GetMapping("/{id}")
    public Result<OmsOrderReturnApplyVo> findOrderReturnApplyById(@PathVariable Integer id){
        //调用方法进行查询
        OmsOrderReturnApplyVo ooRa  = omsOrderReturnApplyService.findOrderReturnApplyById(id);

        return Result.success(ooRa,"操作成功");

    }

    /**
     * 退货申请处理分页查询
     */
    @GetMapping("/list")
    public Result<PageResult<OmsOrderReturnApply>> list(@RequestParam(value = "createTime",required = false) String createTime,
                                   @RequestParam(value = "handleMan",required = false) String handleMan,
                                   @RequestParam(value = "handleTime",required = false) String handleTime,
                                   @RequestParam(value = "id",required = false) Long id,
                                   @RequestParam(value = "pageNum",required = false) Integer pageNum,
                                   @RequestParam(value = "pageSize",required = false) Integer pageSize,
                                   @RequestParam(value = "receiverKeyword",required = false) String receiverKeyword,
                                   @RequestParam(value = "status",required = false) Integer status
                                            ){
        //把接收的参数封装
        OmsOrderReturnApplyDto ooD = new OmsOrderReturnApplyDto();
        ooD.setCreateTime(createTime);
        ooD.setHandleTime(handleTime);
        ooD.setId(id);
        ooD.setHandleMan(handleMan);
        ooD.setReceiverKeyword(receiverKeyword);
        ooD.setPageNum(pageNum);
        ooD.setPageSize(pageSize);
        ooD.setStatus(status);
        //调用方法进行分页查询
       PageResult<OmsOrderReturnApply> pageRe =  omsOrderReturnApplyService.pageOrderReturnApply(ooD);

       return Result.success(pageRe,"操作成功");

    }



}
